﻿package frEngine.util
{
    import com.gengine.global.*;
    import flash.display.*;
    import frEngine.*;
    import frEngine.postProcess.*;

    public class PerformanceUtil extends Object
    {
        private var isAuto:Boolean = true;
        private var writeTextureFlag:int = 0;
        private var drawShadowFlag:int = 1;
        private var stageQualityFlag:int = 0;
        private var writeToTextureTime:Number = -1;
        public var upgradeValue:int = 47;
        public var hasShadowValue:int = 40;
        public var noShadowValue:int = 35;
        private var _hasStart:Boolean = false;
        public static const instance:PerformanceUtil = new PerformanceUtil;

        public function PerformanceUtil()
        {
            return;
        }// end function

        public function start() : void
        {
            this._hasStart = true;
            return;
        }// end function

        public function get flag() : String
        {
            return String(this.writeTextureFlag) + this.drawShadowFlag + this.stageQualityFlag;
        }// end function

        public function downgrade(param1:int) : void
        {
            if (!this.isAuto || !this._hasStart)
            {
                return;
            }
            var _loc_2:* = TimeControler.stageTime;
            if (this.writeTextureFlag == 1)
            {
                if (_loc_2 - this.writeToTextureTime > 900)
                {
                    this.writeTextureFlag = 0;
                    this.writeToTextureTime = _loc_2;
                }
                else
                {
                    this.writeTextureFlag = 2;
                }
                PostProcess.instance.enableWriteToTexture = false;
                return;
            }
            return;
        }// end function

        public function upgrade(param1:int) : void
        {
            if (!this.isAuto || !this._hasStart)
            {
                return;
            }
            var _loc_2:* = TimeControler.stageTime;
            if (this.stageQualityFlag == 0)
            {
                this.stageQualityFlag = 1;
                Global.stage.quality = StageQuality.HIGH;
                return;
            }
            if (this.drawShadowFlag == 0 && param1 > this.hasShadowValue)
            {
                this.drawShadowFlag = 1;
                PostProcess.instance.enabledShadow = true;
                return;
            }
            if (this.writeTextureFlag == 0)
            {
                this.writeTextureFlag = 1;
                PostProcess.instance.enableWriteToTexture = true;
                this.writeToTextureTime = _loc_2;
                return;
            }
            return;
        }// end function

        public function setEffectQulity(param1:int) : void
        {
            var _loc_2:Number = NaN;
            this.isAuto = param1 == 4;
            switch(param1)
            {
                case 1:
                {
                    this.setEffectQuality(StageQuality.LOW, false, false);
                    break;
                }
                case 2:
                {
                    this.setEffectQuality(StageQuality.HIGH, true, false);
                    break;
                }
                case 3:
                {
                    this.setEffectQuality(StageQuality.HIGH, true, true);
                    break;
                }
                case 4:
                {
                    this.setEffectQuality(StageQuality.HIGH, true, false);
                    _loc_2 = TimeControler.stageTime - 3000;
                    this.writeToTextureTime = _loc_2;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function setEffectQuality(param1:String, param2:Boolean, param3:Boolean) : void
        {
            Global.stage.quality = param1;
            PostProcess.instance.enabledShadow = param2;
            PostProcess.instance.enableWriteToTexture = param3;
            this.stageQualityFlag = param1 == StageQuality.HIGH ? (1) : (0);
            this.drawShadowFlag = param2 ? (1) : (0);
            this.writeTextureFlag = param3 ? (1) : (0);
            return;
        }// end function

    }
}
